package com.game.modular.game.battle.process.battleStage.actionPhase.actionPhase2.item;

import cn.hutool.core.util.RandomUtil;
import com.game.modular.game.battle.panel.skill.PanelInfoService;
import com.game.modular.game.battle.info.roundInfo.PvpBattleStatisticsInfoServiceImpl;
import com.game.modular.game.battle.panel.skillEffect.PvpSkillEffectServiceImpl;
import com.game.modular.game.playerAssets.domain.PlayerHero;
import com.game.modular.gameCore.cultivate.domain.CoreSkill;
import com.game.modular.gameCore.cultivate.domain.CoreSkillStar;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import static com.game.modular.game.battle.info.FiledName.SKILL_TYPE_MAP;

/**
 * 4-1 释放技能前
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ReleaseSkillService1 {
    private final PvpBattleStatisticsInfoServiceImpl pvpBattleStatisticsInfoService;
    private final PvpSkillEffectServiceImpl pvpSkillEffectService;
    private final PanelInfoService panelInfoService;

    /**
     * 1. 判定释放
     */
    public boolean determineRelease(
            Long battleId,
            int roundCount,
            int orderOfAction,
            PlayerHero actWJ,
            CoreSkill coreSkill,
            CoreSkillStar coreSkillStar
    ) {
        int release = RandomUtil.randomInt(100) < coreSkillStar.getProbability() ? 1 : 0;
        boolean isRelease = release == 1;
        pvpBattleStatisticsInfoService.countTheNumberOfSkillReleases(battleId, actWJ, coreSkillStar.getId());
        if (isRelease) {
            log.info("技能id:{}({}(类型:{},星阶{}):{})",
                    coreSkill.getId(),
                    coreSkill.getName(),
                    SKILL_TYPE_MAP.get(coreSkill.getType()),
                    coreSkillStar.getId(),
                    coreSkill.getIntro()
            );
        }

        return isRelease;
    }
}
